package com.sywb.chuangyebao.view;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.bean.AlipayWeiXinIsBoundBean;
import com.sywb.chuangyebao.contract.WithDrawContract;
import com.sywb.chuangyebao.utils.ShareUtils;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.bining.footstone.rxjava.rxbus.annotation.Subscribe;
import org.bining.footstone.rxjava.rxbus.annotation.Tag;
import org.bining.footstone.rxjava.rxbus.thread.ThreadMode;
import org.bining.footstone.utils.SharedUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class WithDrawActivity extends ActionbarActivity<WithDrawContract.WithDrawPresenter> implements WithDrawContract.WithDrawView{
    private int onClickId;
    @Override
    public void initView(Bundle bundle) {
        super.initView(bundle);
        setTitle(R.string.withdraw);
    }


    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_withdraw;
    }
    @OnClick({R.id.weixin_withdraw_rl,R.id.alipay_withdraw_rl})
    public void onClick(View view){
        onClickId = view.getId();
        switch (view.getId()){
            case R.id.weixin_withdraw_rl:
            case R.id.alipay_withdraw_rl:
                  mPresenter.alipayWeiXinIsBound();
                 break;
        }
    }
    //绑定微信
    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.HTTP_LOGIN_WEIXIN)})
    public void rxLoginToWX(String code) {
        mPresenter.bindingWeiXin(code);
    }
    //判断微信支付宝是否绑定
    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_ALIPAY_WEIXIN_IS_BOUND)})
    public void alipayWxIsBound(AlipayWeiXinIsBoundBean alipayWeiXinIsBoundBean) {
        if (alipayWeiXinIsBoundBean.getAlipay()==1&&onClickId==R.id.alipay_withdraw_rl){//1绑定 0未绑定
            advance(AlipayWithdrawActivity.class);
        }else if (alipayWeiXinIsBoundBean.getAlipay()==0&&onClickId==R.id.alipay_withdraw_rl){
            advance(AlipayBindingActivity.class);
        }else if (alipayWeiXinIsBoundBean.getWxpay()==1&&onClickId==R.id.weixin_withdraw_rl){
            advance(WeiXinWithdrawActivity.class);
        }else if (alipayWeiXinIsBoundBean.getWxpay()==0&&onClickId==R.id.weixin_withdraw_rl){
            mPresenter.clickBtnWeinxinLogin();
        }
    }
    @Override
    public boolean useRxBus() {
        return true;
    }

    @Override
    public void initPresenter() {
       mPresenter.initPresenter(this);
    }
}
